Skip to main content

Module 3: Terminal Basics, Clone, and SourceTree

Git commands operate on the folder where your terminal is currently located. Checking the path before you begin prevents you from running commands in the wrong project.

What you will learn

  • Navigate folders and create or inspect files from the terminal.
  • Clone a GitHub repository to your computer.
  • Check the current branch, remote URL, and recent versions.
  • Add an existing repository to the SourceTree graphical interface.

Common terminal commands

The following commands work on macOS, Linux, and Git Bash on Windows:

CommandPurposeExample
pwdShow the current pathpwd
lsList filesls
ls -laShow a detailed list, including hidden filesls -la
cd <path>Move to a directorycd projects
cd ..Move to the parent directorycd ..
mkdir <name>Create a directorymkdir practice
touch <file>Create an empty filetouch notes.txt
mv <old> <new>Move or rename a filemv old.txt new.txt
rm <file>Delete a filerm notes.txt
clearClear the terminal displayclear
Be careful with delete commands

Files removed with rm usually do not go to the Recycle Bin or Trash. As a beginner, do not use unfamiliar rm -r or rm -rf commands.

Three path symbols

  • .: the current directory.
  • ..: the parent directory.
  • ~: the current user's home directory.

For example:

cd ~
mkdir git-projects
cd git-projects
pwd

Step 1: Verify your Git identity

git config --global user.name
git config --global user.email

If either command prints nothing, return to Module 1 and configure it. To see which file provides a setting, use:

git config --show-origin --get user.name

Step 2: Get the clone URL

  1. Open the git-practice-remote repository you created in Module 2.
  2. Select Code → Local → SSH.
  3. Copy the URL that begins with [email protected]:.

If SSH is not ready, you can select HTTPS instead. Pushing over HTTPS requires a GitHub-supported authentication method; you cannot use your GitHub account password directly as a Git password.

Step 3: Clone into your project directory

cd ~/git-projects
git clone [email protected]:YOUR_ACCOUNT/git-practice-remote.git
cd git-practice-remote

git clone performs three tasks at once:

  1. Downloads the files.
  2. Downloads the complete Git history.
  3. Creates a remote connection named origin.

Step 4: Check the clone result

pwd
ls -la
git status
git branch --show-current
git remote -v
git log --oneline --decorate -5

You should see that:

  • You are inside the git-practice-remote directory.
  • The current branch is main.
  • origin points to your GitHub repository.
  • git status reports no uncommitted changes.
Check status before acting

Build the habit of running git status before other Git operations. It tells you the current branch, which files have changed, and often suggests the next command.

Step 5: Practice without creating a version

echo "Terminal practice" > terminal-notes.txt
git status
ls -la

terminal-notes.txt is now an untracked file. Do not commit it yet; the next module will guide you through a complete version-creation workflow.

If you do not want to keep the practice file, delete it:

rm terminal-notes.txt
git status

Optional: Open the repository in SourceTree

SourceTree is a graphical interface for Git, but it is not required. Learn the commands first, then use SourceTree as a visual aid for commit graphs and file differences.

  1. Download and install SourceTree from the official SourceTree website.
  2. Open SourceTree and choose the option to add a local repository.
  3. For Browse or Destination Path, select the git-practice-remote folder you cloned.
  4. Add it and confirm that you can see the main branch and commit history.

Button names vary slightly between operating systems and versions. The core idea is always the same: open a folder that already contains a .git directory.

Common problems

fatal: not a git repository

Your terminal is not inside a Git repository. Run pwd, then use cd to enter the correct project directory.

Permission denied (publickey)

SSH authentication is incomplete. Return to Module 2 and check the key, ssh-agent, public key on GitHub, and ssh -T [email protected] in order.

destination path ... already exists

The destination folder already exists. Do not overwrite it. Clone into a different directory name:

git clone <repository-url> git-practice-copy

Command reference

CommandPurpose
git clone <url>Download a remote repository and its complete history
git branch --show-currentShow the current branch
git remote -vShow remote names and URLs
git log --oneline -5Show the five most recent commits
git statusShow the current working state